package com.buaa.aiguangxi.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class InstanceDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 插入一个实例
     * @param sceneId
     * @param isTraining
     * @param instanceName
     * @return
     */
    public int addAnInstance(int sceneId,int isTraining,String instanceName){
        return jdbcTemplate.update("insert into instance(sceneId, isTraining, instanceName, createTime) value (?,?,?,current_timestamp)",sceneId,isTraining,instanceName);
    }

    public List<Map<String,Object>> getInstances(int sceneId,boolean isTraining){
        return jdbcTemplate.queryForList("select * from instance where sceneId=? and isTraining=?",sceneId,isTraining);
    }

    public void stopTraining() {
        jdbcTemplate.update("update instance set isTraining=0 where createTime<current_timestamp");
    }
}
